library(dplyr)
library(ggplot2)
library(plotly)
library(DT)
library(readr)
sales_data <- read_csv("sales_data.csv")
#> Rows: 1410 Columns: 6
#> ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (3): region, category, salesperson
#> dbl (2): units_sold, revenue
#> date (1): date
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sales_data$Date <- as.Date(sales_data$date)
Interactive Plots
p <- ggplot(sales_data, aes(x = region, y = units_sold)) +
geom_boxplot() +
labs(title = "Units Sold by Region")
ggplotly(p)
Interactive Data Table
summary_tbl <- sales_data %>%
group_by(region) %>%
summarize(avg_revenue = mean(revenue, na.rm = TRUE))
datatable(summary_tbl)
Category Data
category_data <- sales_data %>%
filter(category == params$category)
ggplot(category_data, aes(x = Date, y = revenue)) +
geom_line() +
labs(title = paste("Revenue Trend for", params$category))

Conditional Plotting
if (nrow(category_data) > 0) {
ggplot(category_data, aes(x = Date, y = units_sold)) +
geom_col(fill = "skyblue") +
labs(title = paste("Units Sold for", params$category))
} else {
print("No records available for the selected category.")
}
